// pages/today/today.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    target_productivity: 100,
    current_productivity: 80,
    speed: 1.5,
    qualified_num: 77,
    unqualified_num: 3,
    qualified_ratio: 77/80,
    update_time: "2018-09-04 11:10:00",
    imgUrlPre: "https://boansmith.natapp4.cc/images/",
    imgDriverRoom: "name-driver-room.jpg",
    imgTruckTail: "name-truck-tail.jpg",
    imgIndex:1,
    scanResult: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("tody")
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },

  onRefresh: function() {
    var that = this
    wx.request({
      url: "https://boansmith.natapp4.cc/refresh",
      data: {
        'mobile': ""
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      success: function (res) {
        // var message = res.data.msg
        // var code = res.data.code
        // wx.showToast({
        //   title: '请稍候',
        //   icon: 'success',
        //   duration: 3000,
        //   complete: function () {
        //     console.log("comp")
        //     var index = that.data.imgIndex+1
        //     that.setData({
        //       imgIndex: index
        //     })
        //   }
        // })

        wx.showLoading({
          title: '加载中',
        })

        setTimeout(function () {
          wx.hideLoading()
          console.log("comp")
          var index = that.data.imgIndex + 1
          that.setData({
            imgIndex: index
          })
        }, 1000)


      },
      fail: function (res) {
        // fail
        console.log(res)
        that.failMessage()
      },
      complete: function () {
        // complete
        //隐藏loading
        that.setData({
          'getCodeBtnProperty.loading': false
        })
      }
    })
  }, 

  onScan: function() {
    var that = this;
    var scanResult;
    wx.scanCode({
      success: (res) => {
        scanResult = res.result
        that.setData({
          scanResult:scanResult
        })
        wx.showToast({
          title: '扫描成功',
          icon: 'success',
          duration: 2000
        })
      },
      fail: (res) => {
        wx.showToast({
          title: '扫描失败',
          duration: 2000
        })
      },
      complete: (res) => {
      }
    })
  }
})